<template>
	<view class="goods-detail">
		<swiper :indicator-dots="true" :autoplay="false" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in swipers" :key="index">
				<image
					src="https://res.vmallres.com/pimages/uomcdn/CN/pms/202203/gbom/6941487250882/428_428_A1308212EBC5B717A9110FFF9906CC91mp.png"
					mode=""></image>
			</swiper-item>
		</swiper>
		<view class="box1">
			<view class="price">
				<text>￥{{detailInfo.sell_price}}</text>
				<text>￥{{detailInfo.market_price}}</text>
			</view>
			<view class="title">
				{{detailInfo.title}}
			</view>
		</view>
		<view class="line"></view>
		<view class="box2">
			<view class="">
				货号：{{detailInfo.goods_no}}
			</view>
			<view class="">
				库存： {{detailInfo.stock_quantity}}
			</view>
		</view>
		<view class="line"></view>
		<view class="box3">
			<view class="title">
				详情介绍
			</view>
			<view class="content">
				<rich-text :nodes="content"></rich-text>
			</view>
		</view>
		<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
			@buttonClick="buttonClick" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				swipers: [],
				detailInfo: {},
				content: '',
				options: [{
					icon: 'headphones',
					text: '客服'
				}, {
					icon: 'shop',
					text: '店铺',
					info: 2,
					infoBackgroundColor: '#007aff',
					infoColor: "red"
				}, {
					icon: 'cart',
					text: '购物车',
					info: 2
				}],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			}
		},
		methods: {
			async getSwipers() {
				const res = await this.$myRequest({
					url: '/api/getthumimages/' + this.id,
					method: 'get'
				})
				this.swipers = res.data.message
			},
			async getDetailInfo() {
				const res = await this.$myRequest({
					url: '/api/goods/getinfo/' + this.id,
					method: 'get'
				})
				this.detailInfo = res.data.message[0]
			},
			async getDetailContent() {
				const res = await this.$myRequest({
					url: '/api/goods/getdesc/' + this.id,
					method: 'get'
				})
				this.content = res.data.message[0].content
			},
			onClick(e) {
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick(e) {
				console.log(e)
				this.options[2].info++
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getSwipers()
			this.getDetailInfo()
			this.getDetailContent()
		}
	}
</script>

<style lang="scss">
	.goods-detail {
		height: 700rpx;

		swiper {
			width: 100%;
			height: 100%;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.box1 {
			padding: 10px;

			.price {
				font-size: 36rpx;
				color: $uni-main-color;
				line-height: 80rpx;

				text:nth-child(2) {
					color: #ccc;
					font-size: 28rpx;
					text-decoration: line-through;
					margin-left: 20rpx;
				}
			}

			.title {
				font-size: 32rpx;
				line-height: 60rpx;
			}
		}

		.line {
			width: 100%;
			height: 8rpx;
			background-color: #CCCCCC;
		}

		.box2 {
			padding: 0 10px;
			font-size: 32rpx;
			line-height: 70rpx;
		}

		.box3 {
			.title {
				font-size: 32rpx;
				padding-left: 10rpx;
				border-bottom: 1px solid #EEEEEE;
				line-height: 70rpx;
			}

			.content {
				padding: 10px;
				font-size: 28rpx;
				color: #333333;
				line-height: 50rpx;

				img {
					max-width: 100%;
				}
			}
		}
		.uni-goods-nav{
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
		}
	}
</style>
